package com.mz.mattress.admin.service.impl;

import com.mz.mattress.admin.mapper.SaleRatioConfigMapper;
import com.mz.mattress.admin.service.SaleRatioConfigService;
import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.entity.SaleRatioConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Slf4j
@Service
public class SaleRatioConfigServiceImpl implements SaleRatioConfigService {

    @Autowired
    private SaleRatioConfigMapper saleRatioConfigMapper;

    @Override
    public Result<List<SaleRatioConfig>> list() {
        List<SaleRatioConfig> list = saleRatioConfigMapper.list();
        return Result.ok(list);
    }

    @Override
    public Result<SaleRatioConfig> getById(Integer id) {
        SaleRatioConfig saleRatioConfig = saleRatioConfigMapper.selectById(id);
        if (saleRatioConfig == null) {
            return Result.fail("未找到导航图片信息");
        }
        return Result.ok(saleRatioConfig);
    }

    @Override
    public Result add(SaleRatioConfig saleRatioConfig) {
        saleRatioConfigMapper.insert(saleRatioConfig);
        return Result.ok();
    }

    @Override
    public Result updateById(SaleRatioConfig saleRatioConfig) {
        saleRatioConfigMapper.updateById(saleRatioConfig);
        return Result.ok();
    }

    @Override
    public Result deleteByIds(Set<Integer> ids) {
        saleRatioConfigMapper.deleteBatchIds(ids);
        return Result.ok();
    }
}
